.TH std::strstreambuf::setbuf 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::strstreambuf::setbuf \- std::strstreambuf::setbuf

.SH Synopsis
   protected:                                                (deprecated in C++98)
   virtual streambuf* setbuf( char* s, std::streamsize n );  (removed in C++26)

   If s is a null pointer and n is zero, this function has no effect.

   Otherwise, the effect is implementation-defined: some implementations do nothing,
   while some implementations deallocate the dynamic member array used as the buffer
   and begin using the user-supplied character array of size n, whose first element is
   pointed to by s.

   This function is protected virtual, it may only be called through pubsetbuf() or
   from member functions of a user-defined class derived from std::strstreambuf.

.SH Parameters

   s - pointer to the first byte in the user-provided buffer
   n - the number of bytes in the user-provided buffer

.SH Return value

   this

.SH Example

   Implementation test to check if setbuf() is supported on a dynamic strstream (output
   obtained with Sun Studio):


// Run this code

 #include <iostream>
 #include <strstream>

 int main()
 {
     char a[100] = {};
     std::strstream str;
     str.rdbuf()->pubsetbuf(a, sizeof a);
     str << "Test string" << std::ends;
     std::cout << "user-provided buffer holds \\"" << a << "\\"\\n";
 }

.SH Possible output:

 user-provided buffer holds "Test string"

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

     DR   Applied to            Behavior as published               Correct behavior
                     the effect of setbuf() was "performs an
                     operation that is
   LWG 66 C++98      defined separately for each class derived   the effect is
                     from strstreambuf",                         implementation-defined
                     but there are no classes derived from
                     strstreambuf

.SH See also

   pubsetbuf invokes setbuf()
             \fI(public member function of std::basic_streambuf<CharT,Traits>)\fP
   setbuf    replaces the buffer with user-defined array, if permitted
   \fB[virtual]\fP \fI(virtual protected member function of std::basic_streambuf<CharT,Traits>)\fP

   setbuf    attempts to replace the controlled character sequence with an array
   \fB[virtual]\fP \fI\fI(virtual protected member function\fP of\fP
             std::basic_stringbuf<CharT,Traits,Allocator>)
   setbuf    provides user-supplied buffer or turns this filebuf unbuffered
   \fB[virtual]\fP \fI(virtual protected member function of std::basic_filebuf<CharT,Traits>)\fP

